﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using G.Model;

namespace G.Runtime
{
    public class GameEvents : KeyedCollection<string, GameEvent>
    {
        public delegate void GameEventHandler(GameEvent pGameEvent);
        public event GameEventHandler AddedEvent;

        internal GameEvents()
        {
        }

        protected override void InsertItem(int index, GameEvent item)
        {
            base.InsertItem(index, item);
            if (AddedEvent != null)
            {
                AddedEvent(item);
            }
        }

        protected override void RemoveItem(int index)
        {
            GameEvent item = base.Items[index];
            base.RemoveItem(index);
            item.Dispose();
        }

        protected override string GetKeyForItem(GameEvent item)
        {
            return item.Def.Name;
        }

    }
}
